---
sidebar_label: Deployment
---

# Deployment

We strive to make deploying production apps using LangChain.js as intuitive as possible.

## Compatibility

You can use LangChain in a variety of environments, including:

- Node.js (ESM and CommonJS) - 18.x, 19.x, 20.x
- Cloudflare Workers
- Vercel / Next.js (Browser, Serverless and Edge functions)
- Supabase Edge Functions
- Browser
- Deno

Note that individual integrations may not be supported in all environments.

For additional compatibility tips, such as deploying to other environments like older versions of Node, see [the installation section of the docs](/docs/get_started/installation).

## Streaming over HTTP

LangChain is designed to interact with web streaming APIs via LangChain Expression Language (LCEL)'s [`.stream()`](/docs/expression_language/interface#stream) and [`.streamLog()`](/docs/expression_language/interface#stream-log) methods, which both return a web [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) instance
that also implements [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of). Certain modules like [output parsers](/docs/modules/model_io/output_parsers/)
also support "transform"-style streaming, where streamed LLM or chat model chunks are transformed into a different format as they are generated.

LangChain also includes a special [`HttpResponseOutputParser`](/docs/modules/model_io/output_parsers/types/http_response) for transforming LLM outputs into encoded byte streams for `text/plain` and `text/event-stream` content types.

Thus, you can pass streaming LLM responses directly into [web HTTP response objects](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) like this:

import CodeBlock from "@theme/CodeBlock";
import StreamExample from "@examples/guides/deployment/streaming.ts";

<CodeBlock language="typescript">{StreamExample}</CodeBlock>

### Streaming intermediate chain steps

The `.streamLog` LCEL method streams back intermediate chain steps as [JSONPatch](https://jsonpatch.com/) chunks.
See [this page for an in-depth example](/docs/expression_language/interface#stream-log), noting that because LangChain.js works in the browser, you can
import and use the `applyPatch` method from there.

## Error handling

You can handle errors via try/catch for the standard `.invoke()` LCEL method as usual:

import ErrorHandlingExample from "@examples/guides/deployment/error_handling.ts";

<CodeBlock language="typescript">{ErrorHandlingExample}</CodeBlock>

The `.stream()` method will also wait until the first chunk is ready before resolving. This means that you can handle immediate errors that occur with the same pattern:

import StreamErrorHandlingExample from "@examples/guides/deployment/stream_error_handling.ts";

<CodeBlock language="typescript">{StreamErrorHandlingExample}</CodeBlock>

Note that other errors that occur while streaming (for example, broken connections) cannot be handled this way since once the initial HTTP response is sent,
there is no way to alter things like status codes or headers.

## Next steps

- [Next.js](/docs/guides/deployment/nextjs)
- [SvelteKit](/docs/guides/deployment/sveltekit)
- [WebLangChain](https://github.com/langchain-ai/weblangchain/blob/main/nextjs/app/api/chat/stream_log/route.ts), a live deployment of a Next.js backend that uses `streamLog`.
